********************************************************************************
** Do file: g2_consort_numbers.do
** First started: February 19, 2021 
** Last edited: September 8, 2023 

/* Purpose: this do file gathers the number of people for the Experimental Design
figure; i.e. Figure 3 as well as tests of differences in take up rates

Part I: Figure 3 numbers generation
Part II: Tests of differences in take up rates

* ITEM MADE: FIGURE 3
*/

********************************************************************************

clear
clear matrix
clear mata
set maxvar 10000

**************
**  Part I  **
**************

***** FIGURE 3 *****

* Load key dataset
use "$merged/key_rep.dta", clear

* # SMS sent to completed SHS customers
count if k_complete_may==1 // 27081

* # responded to SMS
count if k_complete_may==1 & k_rolling_list==1 // 3300

	/* # What does this look like, by assigned treatment group? 
	Note: group up Secured with Surprise Unsecured since they are offered Secured first */
	tab treatmenttype_sh if k_complete_may==1 & k_rolling_list==1
	
	* Note: Choice not used in this experiment
	
* # Call center reached
* Unsecured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & treatmenttype_sh=="R T2-U" // 855

* Surprise Unsecured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & treatmenttype_sh=="R T1-U" // 821

* Secured 
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & treatmenttype_sh=="R T1-L" // 498
// 821 + 498 = 1319

	* What % of responded to SMS was reached to
	count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 // 2699, or 82% of 3300

	
* # Said yes (not part of the Experimental Design figure)
* Unsecured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_yes_after_interaction==1 & treatmenttype_sh=="R T2-U" // 707

* Surprise Unsecured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_yes_after_interaction==1 & treatmenttype_sh=="R T1-U" // 624

* Secured 
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_yes_after_interaction==1 & treatmenttype_sh=="R T1-L" // 365

	
* # Took loan
* Unsecured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1 & treatmenttype_sh=="R T2-U" // 438

* Surprise Unsecured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1 & treatmenttype_sh=="R T1-U" // 376

* Secured
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1 & treatmenttype_sh=="R T1-L" // 217

	* Across all three main treatments
	count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1 & (treatmenttype_sh=="R T2-U" | treatmenttype_sh=="R T1-U" | treatmenttype_sh=="R T1-L") // 1031

	* Across all three main treatments and control
	count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1 & (treatmenttype_sh=="R T2-U" | treatmenttype_sh=="R T1-U" | treatmenttype_sh=="R T1-L" | treatmenttype_sh=="R C") // 1072

	
* Fact for paper: what % of those who said yes took up loan? Focus on three main treatment groups
* Note that this is not the filtering that will be used in the paper
count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_yes_after_interaction==1 & k_tookloan_repay==1 & (treatmenttype_sh=="R T2-U" | treatmenttype_sh=="R T1-U" | treatmenttype_sh=="R T1-L") // 947

count if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_yes_after_interaction==1 & (treatmenttype_sh=="R T2-U" | treatmenttype_sh=="R T1-U" | treatmenttype_sh=="R T1-L") // 1696

* 947/1696 = 56%


	
******************************************************
	
**************
**  Part 2  **
**************
		
* F test:
g takeup = .
replace takeup = 1 if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1
replace takeup = 0 if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==0
g secured = (treatmenttype_sh=="R T1-L") & k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay!=.
g surpsecured = (treatmenttype_sh=="R T1-U") & k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay!=.
g unsecured = (treatmenttype_sh=="R T2-U") & k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay!=.
reg takeup secured surpsecured unsecured 
test secured = surpsecured = unsecured

* Fact for paper: Compare Secured to Unsecured for takeup
ttest takeup if treatmenttype_sh=="R T1-L" | treatmenttype_sh=="R T2-U", by(treatmenttype_sh) // 0.007

* Fact for paper: Compare Secured to Unsecured for take up (Surprise Secured could be considered with secured at this point)
g treatmenttype_sh2=treatmenttype_sh
replace treatmenttype_sh2 = "R T1-L" if treatmenttype_sh2=="R T1-U"
ttest takeup if treatmenttype_sh2=="R T1-L" | treatmenttype_sh2=="R T2-U", by(treatmenttype_sh2) // 0.004
